// packageTab/pages/meituan/meituan.js
import {
  convert,
  promotion_img,
} from '../../../utils/imapi.js';
import {
  elm_activity_id,
}from '../../../utils/constants.js';
import shareFun from '../../../utils/shareFun.js';
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    img:'https://img.xingkonglian.net/img/common/elm_tg.png',
	img1:'https://img.xingkonglian.net/img/common/elm.jpg',
	show_load: false,
	elm_activity:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	 var elm_activity=elm_activity_id();
	 this.setData({
		 elm_activity:elm_activity
		 })
     console.log(elm_activity);
     
     shareFun.hidenShareMenu()
  },
  async meituan(){
	  console.log(app);
	  
	  
	  //设置登陆权限
	 if (!app.is_auth()) {
	    wx.navigateTo({
	      url: '/pages/login/login',
	    })
	    return;
	  }
	  
	  this.setData({
	    show_load: true
	  })
	  
	  var con=await convert({p:'ELM',content:this.data.elm_activity,uid:app.globalData.uid});
	  
	  console.log(con);
	  
	  
	  var that=this;
	  wx.navigateToMiniProgram({
	    appId: con.data.app_id,
	    path: con.data.wxapp_page_path,
		success(){
			that.setData({
			  show_load: false
			})
		},
		fail(res) {
			that.setData({
			  show_load: false
			})
		}
	  })
	 
  },
  closeDown1() {
    this.setData({
      show_load: false
    })
  },
 async  share(){ // 显示推广海报弹出
     //var index = e.currentTarget.dataset.index
    // console.log(index)
     /*this.setData({
       cur_show_img_index:index,
       is_show_big:1
         })*/
 
     if(!app.is_auth()){
       
       wx.showToast({
         title: '请先登陆，才能生成推广码哦',
       })
 
       wx.navigateTo({
         url: '/pages/login/login',
       })
 
       return
 
     }
 
    wx.showLoading({
      title: '海报生成中...',
    })
 
     const link_data = await promotion_img({
       bg: 'https://img.xingkonglian.net/img/common/elm.jpg',
       opt:2,
       uid:app.globalData.userInfo.uid,
       scene: '10006,'+app.globalData.userInfo.uid //场景，用户uid
     })
     wx.hideLoading()
 
     var le=[];
 	  le.push(link_data.data);
     wx.previewImage({
 		current:link_data.data,
 		urls:le
 	})
 
   },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})